﻿@using Abp.Web.Mvc.Extensions
@using Microsoft.Owin.Security
@model FutureApp.Web.Models.Account.LoginFormViewModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "登录";
}
@section Styles
{
    @Html.IncludeStyle("~/Assets/styles/login.css")
}
@section Scripts
{
    <script type="text/javascript">
        !function ($) {
            var $$$ = function () {
                this.$form = $("#mainForm");
                this.$externalForm = $("#externalForm");
                this.$container = $(".login-container");
                this.$externalBtn = $(".external-btn");
            };
            $$$.prototype = {
                activeContainer: function () {
                    this.$container.addClass("active");
                },
                externalLogin: function () {
                    var self = this;
                    self.$externalBtn.on("click", function (e) {
                        abp.ui.setBusy(
                            self.$container,
                            self.$externalForm.submit()
                        );
                    });
                },
                loginRequest: function () {
                    abp.ui.setBusy(
                        this.$container,
                        abp.ajax({
                            url: this.$form.attr("action"),
                            data: JSON.stringify(this.$form.serializeFormToObject()),
                            type: this.$form.attr("method")
                        })
                    );
                },
                formSubmit: function () {
                    var self = this;
                    self.$form.submit(function (e) {
                        e.preventDefault();
                        self.loginRequest();
                    });
                },
                formKeyBind: function () {
                    var self = this;
                    $("input").on("keydown", function (e) {
                        if (e.keyCode == 13) self.$form.submit();
                    });
                },
                setHash: function () {
                    $("#RetUrlHash").val(location.hash);
                },
                init: function () {
                    var self = this;
                    self.activeContainer();
                    self.formKeyBind();
                    self.setHash();
                    self.formSubmit();
                    self.externalLogin();
                    $("#btnLogin").on("click", function () { self.$form.submit(); });
                }
            };
            $(function () { (new $$$()).init();});
        }(jQuery);
    </script>
}
<div>
    <div class="login-wrapper">
        <div class="login-container">
            <img width="100" height="30" src="~/Assets/images/logo-login@2x.png" />
            <form id="mainForm" action="@Url.Action("Login", "Account")" method="POST">
                @if (Model.IsMultiTenancyEnabled)
                {
                    <div class="form-group">
                        <input name="tenancyName" class="form-control"
                               placeholder="@L("TenancyName")" type="text"
                               maxlength="@FutureApp.MultiTenancy.Tenant.MaxTenancyNameLength">
                    </div>
                }
                else
                {
                    <input name="tenancyName" type="hidden">
                }
                <div class="form-group">
                    <input name="usernameOrEmailAddress" class="form-control"
                           placeholder="@L("UserNameOrEmail")" type="text"
                           maxlength="@FutureApp.Users.User.MaxEmailAddressLength" autofocus>
                </div>
                <div class="form-group">
                    <input name="password" class="form-control"
                           placeholder="@L("Password")" type="password"
                           maxlength="@FutureApp.Users.User.MaxPlainPasswordLength">
                </div>
                <input name="returnUrl" type="hidden" value="@(Model.ReturnUrl)" />
                <input id="RetUrlHash" name="returnUrlHash" type="hidden" />
                <div class="form-options clearfix">
                    <a class="pull-right" href="javascript:void(0);">@L("ForgetPassword")？</a>
                    <div class="text-left">
                        <label class="checkbox checkbox-primary">
                            <input name="rememberMe" type="checkbox" value="true">
                            <span>@L("RememberMe")</span>
                        </label>
                    </div>
                </div>
                <div class="social-login clearfix">
                    <a id="btnLogin" class="btn btn-primary" href="javascript:void(0);">
                        <i class="fa fa-user"></i>
                        <span class="btn-content">@L("LogIn")</span>
                    </a>
                </div>
            </form>
            @{
                var loginProviders = this.Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes().ToList();
            }
            @if (loginProviders.Count > 0)
            {
                <form id="externalForm" action="@Url.Action("ExternalLogin","Account")" method="post" class="external-container">
                    @Html.AntiForgeryToken()
                    <input type="hidden" name="returnUrl" value="@this.Model.ReturnUrl" />
                    @foreach (var provider in loginProviders)
                    {
                        <label class="external-btn">
                            <i class="fa fa-@(provider.AuthenticationType.ToLower())"></i>
                            <input type="radio" class="hidden" name="provider" value="@provider.AuthenticationType">
                        </label>
                    }
                </form>
            }
            <p class="signup">
                还没有账号？<a href="@Url.Action("Register")">@L("Register")</a>
            </p>
        </div>
    </div>
</div>